package Homework3VideoStore;

import java.util.List;

public class Rental
{
	private Customer customer;
	private List<Video> videos;
	private int nightsRented;
	private int amount;
	private int nightToReturn;
	
	public Rental(Customer cust, List<Video> vids, int nights, int dayRented)
	{
		customer = cust;
		videos = vids;
		nightsRented = nights;
		
		amount = calculatePrice();
		nightToReturn = dayRented + nightsRented;
	}
	
	public int calculatePrice()
	{
		int total = 0;
		for (Video video : videos)
		{
			total += (video.getPrice() * nightsRented);
		}
		
		return total;
	}
	
	public List<Video> getVideosInRental()
	{
		return videos;
	}
	
	public int numberOfVideos()
	{
		return videos.size();
	}
	
	public int getNightToReturn()
	{
		return nightToReturn;
	}
	
	public boolean equals(Rental other)
	{
		if(other.numberOfVideos() != numberOfVideos())
			return false;
		
		List<Video> otherVideos = other.getVideosInRental();
		for(Video video : videos)
		{
			if(!otherVideos.contains(video))
				return false;
		}
		
		if(other.getNightToReturn() != getNightToReturn())
			return false;
		
		return true;		
	}
	
	public String toString()
	{
		String retval = "\t" + customer.toString() + " rented " + numberOfVideos() + " on day " + (nightToReturn - nightsRented) +
						" for " + nightsRented + " night.\n";
						
		for(Video video : videos)
		{
			retval += "\t" + video.toString() + "\n";
		}
		
		retval += "\tTotal cost of rental: $" + amount + "\n";

		return retval;
	}
}
